package leecode.算法入门计划.day1;

/**
 * @author cloudJiang
 * @date 2021/10/24 16:21
 */
public class Num704 {
    public static void main(String[] args) {
        System.out.println(search(new int[]{1, 2, 4, 6, 9, 10}, 5));
    }

    public static int search(int[] nums, int target) {
        int left = 0, right = nums.length - 1;

        while (left <= right) {
            int mid = (left + right) / 2;
            int num = nums[mid];

            if (num == target) {
                return mid;
            } else if (num > target) {
                right = mid - 1;
            } else {
                left = mid + 1;
            }
        }
        return -1;
    }
}



